package Vista;

import Datos.Jugador;
import Musica.Audio;
import java.awt.Color;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Sergio Gonzalez
 */
public class Menu extends javax.swing.JFrame {
 
    
    

    @Override
    public void setVisible(boolean b) {
        super.setVisible(b);
        rNormal.setSelected(true);
        rDiana.setSelected(true);
        musica1.setSelected(true);
    }

    public Menu() {
        initComponents();       
    }
   
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        rbgDificultad = new javax.swing.ButtonGroup();
        rbgObjetivo = new javax.swing.ButtonGroup();
        rbgMusica = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        bComenzar = new javax.swing.JButton();
        rFacil = new javax.swing.JRadioButton();
        rNormal = new javax.swing.JRadioButton();
        rDificil = new javax.swing.JRadioButton();
        rChuck = new javax.swing.JRadioButton();
        rDiana = new javax.swing.JRadioButton();
        rCara = new javax.swing.JRadioButton();
        rPato = new javax.swing.JRadioButton();
        rAlien = new javax.swing.JRadioButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        bSalir = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        tJugador = new javax.swing.JTextField();
        lError = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        musica1 = new javax.swing.JRadioButton();
        musica2 = new javax.swing.JRadioButton();
        musica3 = new javax.swing.JRadioButton();
        musica4 = new javax.swing.JRadioButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Menu");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        bComenzar.setText("Comenzar");
        bComenzar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bComenzarActionPerformed(evt);
            }
        });

        rbgDificultad.add(rFacil);
        rFacil.setText("Fácil");
        rFacil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rFacilActionPerformed(evt);
            }
        });

        rbgDificultad.add(rNormal);
        rNormal.setText("Normal");
        rNormal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rNormalActionPerformed(evt);
            }
        });

        rbgDificultad.add(rDificil);
        rDificil.setText("Difícil");
        rDificil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rDificilActionPerformed(evt);
            }
        });

        rbgDificultad.add(rChuck);
        rChuck.setText("Chuck Norris");
        rChuck.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rChuckActionPerformed(evt);
            }
        });

        rbgObjetivo.add(rDiana);
        rDiana.setText("Diana");

        rbgObjetivo.add(rCara);
        rCara.setText("NyanCat");

        rbgObjetivo.add(rPato);
        rPato.setText("Pato");
        rPato.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rPatoActionPerformed(evt);
            }
        });

        rbgObjetivo.add(rAlien);
        rAlien.setText("Alien");

        jLabel2.setFont(new java.awt.Font("Comic Sans MS", 3, 24));
        jLabel2.setText("Dificultad:");

        jLabel3.setFont(new java.awt.Font("Comic Sans MS", 3, 24));
        jLabel3.setText("Objetivos:");

        bSalir.setText("Salir");
        bSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bSalirActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel4.setText("Jugador: ");

        tJugador.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tJugadorKeyTyped(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Comic Sans MS", 3, 24));
        jLabel5.setText("Musica:");

        rbgMusica.add(musica1);
        musica1.setText("Gangnam Style");
        musica1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                musica1ActionPerformed(evt);
            }
        });

        rbgMusica.add(musica2);
        musica2.setText("Imperial March");
        musica2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                musica2ActionPerformed(evt);
            }
        });

        rbgMusica.add(musica3);
        musica3.setText("NyanCat");
        musica3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                musica3ActionPerformed(evt);
            }
        });

        rbgMusica.add(musica4);
        musica4.setText("BennyHill");
        musica4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                musica4ActionPerformed(evt);
            }
        });

        jMenu1.setText("Ayuda");
        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(rNormal)
                            .addComponent(rChuck)
                            .addComponent(rDificil)
                            .addComponent(rFacil)
                            .addComponent(jLabel2))
                        .addGap(53, 53, 53)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(rCara)
                            .addComponent(rDiana)
                            .addComponent(rAlien)
                            .addComponent(rPato)
                            .addComponent(jLabel3))
                        .addGap(56, 56, 56)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(musica3)
                            .addComponent(musica2)
                            .addComponent(musica4)
                            .addComponent(musica1)
                            .addComponent(jLabel5))
                        .addGap(0, 93, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 215, Short.MAX_VALUE)
                        .addComponent(jLabel1)
                        .addGap(327, 327, 327))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tJugador, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(388, Short.MAX_VALUE))))
            .addComponent(lError, javax.swing.GroupLayout.DEFAULT_SIZE, 574, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(75, 75, 75)
                .addComponent(bComenzar, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(85, 85, 85)
                .addComponent(bSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 41, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(lError)
                .addGap(12, 12, 12)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tJugador, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel5))
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rFacil)
                    .addComponent(rDiana)
                    .addComponent(musica1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rNormal)
                    .addComponent(rCara)
                    .addComponent(musica2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rDificil)
                    .addComponent(rPato)
                    .addComponent(musica3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rChuck)
                    .addComponent(rAlien)
                    .addComponent(musica4))
                .addGap(17, 17, 17)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bComenzar, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(20, 20, 20))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void bComenzarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bComenzarActionPerformed
       
        if(tJugador.getText().length() == 0){
            lError.setForeground(Color.red);
            lError.setText("Debe introducir el NOMBRE del jugador");
        }else{
     
          int num;
            
        //musica
        if(musica1.isSelected()){
            num = 1;
        } else if(musica2.isSelected()){
            num = 2;
        } else if(musica3.isSelected()){
           num = 3;
        } else if(musica4.isSelected()){
            num = 4;
        } else {
            num =-1;
        }
            
         Gameview gv = new Gameview(num);
         
        //dificultad
        if(rFacil.isSelected()){
            gv.dificultad = 1;
        }
        if(rNormal.isSelected()){
            gv.dificultad = 2;
        }
        if(rDificil.isSelected()){
           gv.dificultad = 3;
        }
        if(rChuck.isSelected()){
            gv.dificultad = 4;
        }
        
        //objetivo 
         if(rDiana.isSelected()){
            gv.objetivo = 1;
        }
        if(rCara.isSelected()){
            gv.objetivo = 2;
        }
        if(rPato.isSelected()){
           gv.objetivo = 3;
        }
        if(rAlien.isSelected()){
            gv.objetivo = 4;
        }
        
 
        
         gv.nombre= tJugador.getText();

        gv.setVisible(true);      
        this.setVisible(false);
        //this.dispose();
       }
    }//GEN-LAST:event_bComenzarActionPerformed
    public Audio setCancion(int n){
        //Audio a =new Audio("gangnam.wav");
        Audio a;
        switch(n){
            case 1:a=new Audio("gangnam.wav");break;
            case 2:a=new Audio("imperial.wav");break;
            case 3:a=new Audio("nyan.wav");break;
            case 4:a=new Audio("benny.wav");break;   
            default:a=new Audio("gangnam.wav");break;    
        }
        return a;
    }
    private void rPatoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rPatoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_rPatoActionPerformed

    private void rNormalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rNormalActionPerformed
        // TODO add your handling code here:
        rDiana.setEnabled(true);
        rCara.setEnabled(true);
        rPato.setEnabled(true);
        rAlien.setEnabled(true);
        
    }//GEN-LAST:event_rNormalActionPerformed

    private void bSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bSalirActionPerformed
        // TODO add your handling code here:
       int resp =JOptionPane.showConfirmDialog(this,"Esta seguro que desea SALIR","Salir",JOptionPane.YES_NO_OPTION);
       if(resp == JOptionPane.YES_OPTION ){
           System.exit(0);
       }
        
    }//GEN-LAST:event_bSalirActionPerformed
   
    private void tJugadorKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tJugadorKeyTyped
        // TODO add your handling code here:
        if (tJugador.getText().length() == 3){
            evt.consume();
        }
    }//GEN-LAST:event_tJugadorKeyTyped

    private void rChuckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rChuckActionPerformed
        // TODO add your handling code here:
        rDiana.setEnabled(false);
        rCara.setEnabled(false);
        rPato.setEnabled(false);
        rAlien.setEnabled(false);
               
    }//GEN-LAST:event_rChuckActionPerformed

    private void rDificilActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rDificilActionPerformed
        // TODO add your handling code here:
        rDiana.setEnabled(true);
        rCara.setEnabled(true);
        rPato.setEnabled(true);
        rAlien.setEnabled(true);
    }//GEN-LAST:event_rDificilActionPerformed

    private void rFacilActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rFacilActionPerformed
        // TODO add your handling code here:
        rDiana.setEnabled(true);
        rCara.setEnabled(true);
        rPato.setEnabled(true);
        rAlien.setEnabled(true);
    }//GEN-LAST:event_rFacilActionPerformed

    private void musica3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_musica3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_musica3ActionPerformed

    private void musica2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_musica2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_musica2ActionPerformed

    private void musica1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_musica1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_musica1ActionPerformed

private void musica4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_musica4ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_musica4ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
       
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Menu().setVisible(true);
            }
        });
       
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bComenzar;
    private javax.swing.JButton bSalir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JLabel lError;
    private javax.swing.JRadioButton musica1;
    private javax.swing.JRadioButton musica2;
    private javax.swing.JRadioButton musica3;
    private javax.swing.JRadioButton musica4;
    private javax.swing.JRadioButton rAlien;
    private javax.swing.JRadioButton rCara;
    private javax.swing.JRadioButton rChuck;
    private javax.swing.JRadioButton rDiana;
    private javax.swing.JRadioButton rDificil;
    private javax.swing.JRadioButton rFacil;
    private javax.swing.JRadioButton rNormal;
    private javax.swing.JRadioButton rPato;
    private javax.swing.ButtonGroup rbgDificultad;
    private javax.swing.ButtonGroup rbgMusica;
    private javax.swing.ButtonGroup rbgObjetivo;
    private javax.swing.JTextField tJugador;
    // End of variables declaration//GEN-END:variables
}
